package br.com.bb.robot.controller;

import br.com.bb.robot.model.FileIO;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;

public class FileIOController {

   private FileIO fileIO;

    public FileIOController() {
    }
//     public void analyzePath() {
//        File file = getFile();
//        if (file.exists()) {
//            if (file.isFile()) {
//                JOptionPane.showMessageDialog(this, file.getName(), "© Banco do Brasil", JOptionPane.OK_OPTION);
//            } else {
//                JOptionPane.showMessageDialog(this, "Arquivo inválido", "© Banco do Brasil", JOptionPane.ERROR_MESSAGE);
//                System.exit(1);
//            }
//        }
//    }

    public void loadFile() throws FileNotFoundException {
        String text = "";
        String str;
        try {
            BufferedReader in = new BufferedReader(new FileReader(fileIO.getFile()));
            while ((str = in.readLine()) != null) {
                text += str;
                text += "\n";
            }
            in.close();
            fileIO.setText(text);
        } catch (Exception e) {
            System.out.println(e);
        }
    }
    
    public void setFile(File file) {
       fileIO.setFile(file);
    }
    
    public String getText() {
        return fileIO.getText();
    }
}
